<?php
use think\Db;
?>
<!doctype html>
<html>
<head>
{include file="Public:head" /}
<script src="__THEMES__/js/jquery.js"></script>
</head>
<body>
	<div class="wrap">
		{include file="Public:header" /}
		<script>
		layui.use('element', function(){
			var $ = layui.jquery,element = layui.element; 
			element.progress('progress', '80%');
		});
		</script>
		<section class="section">
			<div class="step">
				<ul class="unstyled">
					<li class="on"><em>1</em>检测环境</li>
					<li class="on"><em>2</em>创建数据</li>
					<li class="current"><em>3</em>完成安装</li>
				</ul>
			</div>
			<div class="install" id="log">
				<ul id="loginner" class="unstyled"></ul>
			</div>
			<div class="bottom text-center">
				<a href="javascript:;"><i class="fa fa-refresh fa-spin"></i>&nbsp;正在安装...</a>
			</div>
		</section>
		
		<script type="text/javascript">
			function showmsg(content,status){
				var icon='<i class="fa fa-check correct"></i> ';
				if(status=="error"){
					icon ='<i class="fa fa-remove error"></i> ';
				}
				$('#loginner').append("<li>"+icon+content+"</li>");
				$("#log").scrollTop(1000000000);
			}

			var database='{$data}',install_sql_index=0;
			
			if(typeof database == 'string'){
				try{
		    		var database = JSON.parse(database);
		    		if(typeof database == 'object' && database){
			    		
				    }else{
				    	showmsg("非法数据安装","error");
				    }
		    	}catch(e){
		    		showmsg("非法数据安装","error");
		    	}
			}else{
				showmsg("非法数据安装","error");
			}

			//database=eval('('+database+')');

			function install(data){
				$.ajax({
					url:"{:url('install/index/install')}",
					dataType:"json",
					type:"post",
					data:data,
					success:function(data){
						showmsg(data.msg,data.data.status);
						database.action=data.data.action;
						if(data.data.status=="success"){
							if(data.data.action == undefined){
								setInterval(function(){
									location.href='/install/index/step5'	
								},1000);
							}else{
								if(data.data.action=="executeSql") database.install_sql_index=install_sql_index++;
								install(database);
							}
						}else{
							return false;
						}
					},
					error: function (XMLHttpRequest, textStatus, errorThrown){

               	 	}
				});
			}

			function installDb(){
				database.action="database";
				install(database);
			}

			installDb();

		</script>
	</div>
	{include file="Public:footer" /}
</body>
</html>